package com.Web.Session;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SessionServletdemo1", value = "/SessionServletdemo1")
public class  SessionServletdemo1 extends HttpServlet {

//    Session:在一次会话的多次请求之间共享数据，将数据保存到服务器端
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 1.通过rquest对象，获取session对象
    HttpSession session = request.getSession();
    // 2.操作session的API，获取数据
    String username = (String) session.getAttribute("username");
    System.out.println("getSession获取：" + username);
    }
}

